﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AMS.DataAccess.Sys.Interfaces;
using Spring.Context;
using Spring.Context.Support;
using AMS.DataAccess.Common;
using AMS.DataAccess.Sys.Filters;
using AMS.DataAccess.Sys.BO;
using AMS.DataAccess.Filter;

namespace AMS.Sys.WinForms
{
    public partial class FrmUsers2 : AMS.UI.Forms.BaseForm
    {
        public FrmUsers2()
        {
            InitializeComponent();
            // ApplyDelayLoadData();
            DoDataBind();
        }

        protected override void DelayLoadData()
        {

            DoDataBind();
        }

        private void pager_PageIndexChanged(object sender, EventArgs e)
        {
            DoDataBind();
        }

        private void DoDataBind()
        {
            IApplicationContext context =  ContextRegistry.GetContext();
            IUserManager userMgr = (IUserManager)context.GetObject("UserManager");

            UserFilter filter = new UserFilter();
            if (!string.IsNullOrEmpty(txtKeyword.TextBox.Text))
            {
                filter.Name = new StringFilterField(txtKeyword.TextBox.Text);
            }

            List<UserInfo> users = userMgr.GetPagedUsers(Globals.Context, filter , pager.CurrentPageIndex, pager.PageSize);
            dgv.DataSource = users;
        }

    }
}
